package com.ankang.art.controller;

import com.ankang.art.dto.ExaminationDto;
import com.ankang.art.dto.addStudentToExamTestDto;
import com.ankang.art.pto.ExaminationPto;
import com.ankang.art.service.ExaminationService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Author:
 * Date:2020/3/17    20:42
 */
@Controller
@RequestMapping("/art/management/sts")
@CrossOrigin
public class ExaminationController {

    @Autowired
    ExaminationService examinationService;

    @GetMapping("/deleteExamination")
    public ResponseEntity deleteExamination(@RequestParam(value = "name") String name){

        if(null == name){
            throw new RuntimeException("id不能为空");
        }

        examinationService.deleteExamination(name);

        return new ResponseEntity(HttpStatus.OK);
    }
    @GetMapping("/getExamination")
    public ResponseEntity getJudges(@RequestParam(value = "name" ,required = false) String name,
                                    @RequestParam(value = "status" ,required = false) String status,
                                    @RequestParam(value = "beginTime" ,required = false) Long beginTime,
                                    @RequestParam(value = "endTime" ,required = false) Long endTime,
                                    @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize" ,defaultValue = "10") Integer pageSize){

        PageHelper.startPage(pageNo, pageSize);

        return new ResponseEntity(examinationService.getExamination(name, status, beginTime, endTime),HttpStatus.OK);
    }

    @PostMapping("/savaExamination")
    public ResponseEntity savaJudges(@RequestBody ExaminationPto examinationPto){

        examinationService.savaExamination(examinationPto);


        return new ResponseEntity(HttpStatus.OK);
    }

    @PostMapping("/updateExamination")
    public ResponseEntity updateJudges(@RequestBody ExaminationDto examinationDto){

        examinationService.updateExamination(examinationDto);

        return new ResponseEntity(HttpStatus.OK);
    }


    @PostMapping("addStudentToExamTest")
    public ResponseEntity addStudentToExamTest(@RequestBody addStudentToExamTestDto addStudentToExamTestDto){

       Boolean flag =  examinationService.addStudentToExamTest(addStudentToExamTestDto);

        return new ResponseEntity(HttpStatus.OK);
    }

}
